SELECT 
	SalesOrderNumber,
	T1.LineCount
FROM
	(
		SELECT
			SalesOrderID,
			COUNT(*) AS LineCount
		FROM
			Sales.SalesOrderDetail
		GROUP BY
			SalesOrderID
	) T1
	INNER JOIN
	Sales.SalesOrderHeader
		ON T1.SalesOrderID = SalesOrderHeader.SalesOrderID